package com.wanlian.router.ui.integral;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.smart.android.ui.tools.MyNiuBAdapter;
import com.smart.android.utils.DateTime;
import com.wanlian.router.R;
import com.wanlian.router.bean.IntegralFlow;

import java.math.BigDecimal;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;

/**
 * Created by Hyu on 2018/9/8.
 * Email: fvaryu@163.com
 */
public class IncomeFlowAdapter extends MyNiuBAdapter<IntegralFlow> {

    public IncomeFlowAdapter(Context context, List<IntegralFlow> mTs) {
        super(context, mTs);
    }

    @Override
    public int layout() {
        return R.layout.layout_item_income_flow;
    }

    @Override
    public MyViewHolder<IntegralFlow> holder(View view) {
        return new FlowHolder(view);
    }

    class FlowHolder extends MyViewHolder<IntegralFlow> {

        @BindView(R.id.tv_title)
        TextView tv_title;
        @BindView(R.id.tv_amount)
        TextView tv_amount;
        @BindView(R.id.tv_time)
        TextView tv_time;
        @BindView(R.id.tv_from)
        TextView tv_from;

        public FlowHolder(View view) {
            super(view);
        }

        @Override
        public void setData(int i, IntegralFlow integralFlow) {
            tv_title.setText(integralFlow.getStype());

            if (TextUtils.isEmpty(integralFlow.getPname())) {
                tv_from.setText(null);
            }else {
                tv_from.setText(String.format(integralFlow.getRankType() == 0 ? "设备ID:%s" : "%s", integralFlow.getPname()));
            }
            long a = (long)(integralFlow.getScore() * 10000000);
            tv_amount.setText(String.format(Locale.getDefault(), "%s%.6f", a > 0 ? "+" : "", integralFlow.getScore()));
            if (a > 0) {
                tv_amount.setTextColor(Color.parseColor("#18DAAE"));
            }else {
                tv_amount.setTextColor(ContextCompat.getColor(tv_amount.getContext(), R.color.color_red));
            }
            tv_time.setText(DateTime.getDateByType(integralFlow.getAddtime(), "yyyy.MM.dd HH:mm"));
        }
    }
}
